{extend name="public:base"}
{block name="main"}
<form class="layui-form">
  <div class="demoTable">
    条件搜索：
    <div class="layui-inline">
      <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入关键字">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="start" id="start"  placeholder="请输入评论开始时间">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="end" id="end"  placeholder="请输入评论结束时间">
    </div>

    <button class="layui-btn" data-type="reload" lay-filter="submit" lay-submit>搜索</button>
    <button class="layui-btn layui-btn-primary" type="reset" data-type="reload" lay-filter="reset" lay-submit>重置</button>

  </div>
</form>
<table class="layui-table" lay-data="{height:650,url:location.href,where:{newsid:'{:input('newsid')}'}, page:true, id:'comment'}" lay-filter="table">
  <thead>
    <tr>
      <th lay-data="{field:'id', sort: true}">ID</th>
      <th lay-data="{field:'title'}">新闻标题</th>
      <th lay-data="{field:'avatar',templet:'#avatar'}">用户头像</th>
      <th lay-data="{field:'nickname'}">昵称</th>
      <th lay-data="{field:'content'}">评论内容</th>
      <th lay-data="{field:'status',templet:'#status'}">状态</th>
      <th lay-data="{field:'addtime', sort: true}">评论时间</th>
      <th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>

<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;
   laydate.render({
      elem: '#start',
      max: 0
   });
    laydate.render({
      elem: '#end',
      max: 1
   });
   
  var $ = layui.$;

  //搜索
  form.on('submit(submit)', function(data){

    var keyword=$("input[name='keyword']").val();
    var start=$("input[name='start']").val();
    var end=$("input[name='end']").val();
    var cateid=$("select[name='cateid']").val();
    var id=$("select[name='id']").val();
    var wheretype=$("select[name='wheretype']").val();
    
    
    table.reload('comment', {
    where: { 
      keyword:keyword,
      start:start,
      end:end,
      cateid:cateid,
      id:id,
      wheretype:wheretype
    }
  });

    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });




  table.on('tool(table)', function(obj){
    var data = obj.data;

    if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('commentdel')}",{'id': data.id},function(data){
           if(data=='1'){
              alert("操作成功~");
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="/admin.php/news/newsinfo/newsid/"+data.newsid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    }
  });

  //开关
  form.on('switch(status)', function(data){

    var name=$(this).attr('name');

    $.post("{:url('commentup')}",{type:name,value:data.elem.checked,'id':data.value},function(res){
      if(res=='0'){
        alert("操作失败");
      }
    });
   
  }); 

  //图片查看
  layer.photos({
    photos: 'div'
    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });


});

</script>


<script type="text/html" id="link">
  {{#  if(d.url != '' && typeof(d.url) != 'undefined'){ }}
     <a href="{{d.url}}" class="layui-table-link" target="_blank">{{d.title}}</a>
  {{#  } else { }}
    {{d.title}}
  {{#  } }}
</script>
<script type="text/html" id="avatar">
  <img src='{{d.avatar}}'>
</script>


<script type="text/html" id="status">
  {{#  if(d.status == 1){ }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" value="{{d.id}}" checked>
  {{#  } else { }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status"  value="{{d.id}}">
  {{#  } }}
</script>




{/block}